import Vue from 'vue'
import Router from 'vue-router'
import AdminLogin from '../components/admin/AdminLogin.vue'
import AdminUpdate from '../components/admin/AdminUpdate.vue'
import AdminAdd from '../components/admin/AdminAdd'
import AdminList from "../components/admin/AdminList";
import Hello from '../components/Hello'
import UserList from '../components/user/UserList'
import AdminSelf from '../components/admin/AdminSelf'
import UserUpdate from '../components/user/UserUpdate'
import Goods from '../components/goods/Goods'
import GoodsAdd from '../components/goods/GoodsAdd'
import Commodity from '../components/commodity/Commodity'
import GoodsUpdate from '../components/goods/GoodsUpdate'
import CommodityAdd from '../components/commodity/CommodityAdd'
import CommodityUpdate from '../components/commodity/CommodityUpdate'
import Order from '../components/order/Order'
import OrderUnSend from '../components/order/OrderUnSend'
import OrderUpdate from '../components/order/OrderUpdate'
import OrderSending from '../components/order/OrderSending'
import CommodityDetail from '../components/commodity/CommodityDetail'
import OrderSuccess from '../components/order/OrderSuccess'
import HotWords from '../components/page/hotwords/HotWords'
import HotWordAdd from '../components/page/hotwords/HotWordAdd'
import HotWordUpdate from '../components/page/hotwords/HotWordUpdate'
import New from '../components/page/new/New'
import NewUpdate from '../components/page/new/NewUpdate'
import NewAdd from '../components/page/new/NewAdd'
import Photo from '../components/lunbo/Photo'
import PhotoAdd from '../components/lunbo/PhotoAdd'
import PhotoUpdate from '../components/lunbo/PhotoUpdate'
Vue.use(Router)

const router = new Router({
  routes: [
    {
      path: '/',
      name: 'Hello',
      component: Hello
    },
    {
      path: '/login',
      name: 'AdminLogin',
      component: AdminLogin
    },
    {
      path: '/admin/update/:id',
      name: 'AdminUpdate',
      component: AdminUpdate
    },
    {
      path: '/admin/add',
      name: 'AdminAdd',
      component: AdminAdd
    },
    {
      path: '/admin/list',
      name: 'AdminList',
      component: AdminList
    },

    {
      path: '/user/list',
      name: 'UserList',
      component: UserList
    },
    {
      path: '/admin/self',
      name: 'AdminSelf',
      component: AdminSelf
    },

    {
      path: '/user/update/:id',
      name: 'UserUpdate',
      component: UserUpdate
    },
    {
      path: '/goods/list',
      name: 'Goods',
      component: Goods
    },
    {
      path: '/goods/add',
      name: 'GoodsAdd',
      component: GoodsAdd
    },
    {
      path: '/goods/update/:id',
      name: 'GoodsUpdate',
      component: GoodsUpdate
    },
    {
      path: '/commodity/list',
      name: 'Commodity',
      component: Commodity
    },
    {
      path: '/commodity/add',
      name: 'CommodityAdd',
      component: CommodityAdd
    },
    {
      path: '/commodity/update/:id',
      name: 'CommodityUpdate',
      component: CommodityUpdate
    },
    {
      path: '/order/list',
      name: 'Order',
      component: Order
    },
    {
      path: '/order/unSend',
      name: 'OrderUnSend',
      component: OrderUnSend
    },
    {
      path: '/order/update/:id',
      name: 'OrderUpdate',
      component: OrderUpdate
    },
    {
      path: '/order/sending',
      name: 'OrderSending',
      component: OrderSending
    },
    {
      path: '/commodity/detail/:id',
      name: 'CommodityDetail',
      component: CommodityDetail
    },
    {
      path: '/order/success',
      name: 'OrderSuccess',
      component: OrderSuccess
    },
    {
      path: '/page/hotword',
      name: 'HotWords',
      component: HotWords
    },
    {
      path: '/page/hotwordAdd',
      name: 'HotWordAdd',
      component: HotWordAdd
    },
    {
      path: '/page/hotwordUpdate/:id',
      name: 'HotWordUpdate',
      component: HotWordUpdate
    },
    {
      path: '/page/newUpdate/:id',
      name: 'NewUpdate',
      component: NewUpdate
    },
    {
      path: '/page/newAdd',
      name: 'NewAdd',
      component: NewAdd
    },
    {
      path: '/page/new',
      name: 'New',
      component: New
    },

    {
      path: '/lunbo/photoUpdate/:id',
      name: 'PhotoUpdate',
      component: PhotoUpdate
    },
    {
      path: '/lunbo/photoAdd',
      name: 'PhotoAdd',
      component: PhotoAdd
    },
    {
      path: '/lunbo/photo',
      name: 'Photo',
      component: Photo
    },
  ]
})
// 挂载路由导航守卫,to表示将要访问的路径，from表示从哪里来，next是下一个要做的操作 next('/login')强制跳转login
router.beforeEach((to, from, next) => {
  // 访问登录页，放行
  if (to.path === '/login') return next()
  // 获取token
  const tokenStr = window.sessionStorage.getItem('user')
  // 没有token, 强制跳转到登录页
  if (!tokenStr) return next('/login')
  next()
})

export default router
